package algorithmExample;

/**
 * @author: zhang.rongqing
 * @since: 2019/10/31
 */
//题目地址：https://leetcode-cn.com/problems/container-with-most-water/
public class ContainerWithMostWater {

    public int maxArea(int[] height) {
        int result = 0;
        if (height.length < 1) {
            return 0;
        }

        for (int start = 0; start < height.length - 1; start++) {
            result = Math.max(result, maxAreaFromStart(height, start));
        }
        return result;
    }

    private int maxAreaFromStart(int[] height, int start) {
        int maxArea = 0;
        for (int i = start + 1; i < height.length; i++) {
            maxArea = Math.max(maxArea, (i - start) * Math.min(height[i], height[start]));
        }
        return maxArea;
    }

    public static void main(String[] args) {
        int[] input = new int[]{1, 1};
        ContainerWithMostWater containerWithMostWater = new ContainerWithMostWater();
        int result = containerWithMostWater.maxArea(input);
        System.out.println(String.format("input:%s,maxArea is %s", input, result));
    }

}
